/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package chat.server;

import chat.common.*;
import java.lang.*;
import java.net.*;
import java.io.*;
import java.util.*;

/**
 * Channel of the application
 * @author berthise
 */
public class Channel {

    private HashSet<String> vectClient = new HashSet();
    private String name;
    private CommunicationsManager parent = null;

    public Channel(String name, CommunicationsManager parent) {
        this.name = name;
        this.parent = parent;
        // vectClient.add(com);
    }

    public void addClient(String client) {
        vectClient.add(client);
    }

    public void removeClient(String client) {
        vectClient.remove(client);
    }

    public void sendMessage(Message mess) {
        String src = mess.getSrc();
        //   String dest = mess.getDest();
        //    mess.setDest(mess.getSrc());
        mess.revertSrcDest();
        for (String com : vectClient) {
            if (!com.equals(src)) {
                //        mess.setSrc(dest);
                try {
                    mess.sendMessage(parent.getCommunication(com).getSortie());
                } catch (Exception e) {
                    System.out.println("error closeclient" + e.toString());
                }
            }
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public HashSet<String> getVectClient() {
        return vectClient;
    }

    public void setVectClient(HashSet<String> vectClient) {
        this.vectClient = vectClient;
    }

    public boolean isEmpty() {
        return vectClient.isEmpty();
    }
}
